package com.help.config;

import com.help.common.interceptors.UserInterceptor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 拦截器的注册
 * @author 风亦未止
 * @date 2021/9/20 23:21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Component
@ConfigurationProperties(prefix="intercept")
public class MvcConfig implements WebMvcConfigurer {

    private List<String> urls;

    /*** 通过@Bean注解，将我们定义的拦截器注册到Spring容器 * @return */
    public UserInterceptor userInterceptor() {
        return new UserInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.userInterceptor()).addPathPatterns(urls);
    }
}
